import { message } from 'antd';
const baseUrl='http://jacklv.cn'
export default function request(url,option={}){
    return fetch(baseUrl+url,{
        method:option.method?option.method:'get',
        body:JSON.stringify(option.body),
        headers: {
            'Content-Type': 'application/json',
            token:localStorage.token
          }
    }).then(response=>{
        
        switch (response.status) {
            case 200:
                return response.json()
            case 401:
                message.error('登录过期')
                localStorage.clear()
                location.href='#/login'
                return Promise.reject(response)
                
            default:
                return Promise.reject(response)
                
        }

    }).then(res=>{
        if (res.code===1) {
            
            return res.data
        }else{
            message.error(res.msg || "网络问题")
            return Promise.reject(res)
        }
    })
}